<template>
  <div class="dashboard">
    <el-row :gutter="10">
      <el-col :span="7">
        <cky-card title="分类商品数量(饼图)">
          <PieEchart :pieData="categoryGoodsCount" />
        </cky-card>
      </el-col>
      <el-col :span="10">
        <cky-card title="不同城市商品销量">
          <MapEchart :mapData="addressGoodsSale" />
        </cky-card>
      </el-col>
      <el-col :span="7">
        <cky-card title="分类商品数量(玫瑰图)">
          <rose-echart :roseData="categoryGoodsCount" />
        </cky-card>
      </el-col>
    </el-row>
    <el-row :gutter="10">
      <el-col :span="12">
        <cky-card title="分类商品的销量">
          <LineEchart v-bind="categoryGoodsSale" />
        </cky-card>
      </el-col>
      <el-col :span="12">
        <cky-card title="分类商品的收藏">
          <BarEchart v-bind="categoryGoodsFavor" />
        </cky-card>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts" setup>
import { useStore } from '@/store'
import { computed } from 'vue'

import ckyCard from '@/base-ui/card'
import {
  PieEchart,
  LineEchart,
  RoseEchart,
  BarEchart,
  MapEchart
} from '@/components/page-echarts'

const store = useStore()
store.dispatch('dashboard/getDashboardDataAction')

const categoryGoodsCount = computed(() => {
  return store.state.dashboard.categoryGoodsCount.map((item: any) => {
    if (item.goodsCount) return { name: item.name, value: item.goodsCount }
  })
})

const categoryGoodsSale = computed(() => {
  const xLabels: string[] = []
  const values: any[] = []
  const categoryGoodsSale = store.state.dashboard.categoryGoodsSale
  for (const item of categoryGoodsSale) {
    if (item.goodsCount) {
      xLabels.push(item.name)
      values.push(item.goodsCount)
    }
  }
  return { xLabels, values }
})

const categoryGoodsFavor = computed(() => {
  const xLabels: string[] = []
  const values: any[] = []
  const categoryGoodsFavor = store.state.dashboard.categoryGoodsFavor
  for (const item of categoryGoodsFavor) {
    if (item.goodsFavor) {
      xLabels.push(item.name)
      values.push(item.goodsFavor)
    }
  }
  return { xLabels, values }
})

const addressGoodsSale = computed(() => {
  return store.state.dashboard.addressGoodsSale.map((item: any) => {
    return { name: item.address, value: item.count }
  })
})
</script>

<style scoped></style>
